'use strict';

const Controller = require('egg').Controller;
const path = require('path');
const fse = require('fs-extra');
const toPdf = require("office-to-pdf");
const fs = require("fs");
const await = require('await-stream-ready/lib/await');

class UploadController extends Controller {
  async index() {
    const { ctx } = this;
    const files = ctx.request.files;
    if (files.length <= 0) {
      ctx.body = { code: 400, msg: '文件为空', status: 'failure' };
      return;
    }
    const result = await ctx.service.file.uploadFile(files[0], ctx.request.body);
    ctx.body = result;
  }
  async deleteFile() {
    const { ctx } = this;
    const { file_id } = ctx.params;
    const result = await ctx.service.file.deleteFile(file_id);
    ctx.body = result;
  }
}

module.exports = UploadController;
